package com.teacher.client;

import com.teacher.entity.Student;
import com.teacher.entity.Teacher;
import com.teacher.util.Datas;
import com.teacher.util.SysConstants;

import java.util.List;
import java.util.Scanner;

/**
 * Client--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2017-09-25 16:55
 **/
public class Client {

    private static Scanner scan = new Scanner(System.in);

    private static ClientBiz clientBiz = new ClientBiz();

    public static void main(String[] args) {

        System.out.println("======操作学员系统，请先登录=======");
        System.out.println("1.登录\n2.退出系统");
        System.out.println("===请选择数字1/2===");
        int num = scan.nextInt();
        if (num == 1) {
            createLoginView();
        }
        System.out.println("系统终止");
    }

    public static void createLoginView() {

        while (true) {
            System.out.println("用户名：");
            String userName = scan.next();
            System.out.println("用户密码：");
            String password = scan.next();

            Datas datas = clientBiz.doLogin(userName, password);
            if (SysConstants.SYS_SUCCESS.getName().equals(datas.getFlag())) {
                System.out.println("====登录成功，进入学员管理界面===");
                createStudentManagerView(datas.getTeacher());
                break;
            } else {
                System.out.println("用户名或者密码输入错误，请重新输入");
            }
        }
    }

    public static void createStudentManagerView(Teacher teacher) {

        while (true) {

            System.out.println("===学员信息管理界面===");
            System.out.println("1.查看学员信息\n2.更新学员评语\n3.删除学员信息\n4.退出系统");
            System.out.println("===请选择数字1，2，3，4====");

            int num = scan.nextInt();

            switch (num) {
                case 1:
                    Datas datas = clientBiz.doFind(teacher.getId());
                    if (SysConstants.SYS_SUCCESS.getName().equals(datas.getFlag())) {

                        List<Student> students = datas.getStudents();
                        System.out.println("====================================");
                        System.out.println("编号\t姓名\t年龄\t性别\t老师\t评语");
                        for (Student student : students) {
                            System.out.println(student.getStuId()+"\t"
                            +student.getStuName()+"\t"
                            +student.getStuAge()+"\t"
                            +(student.getStuSex()==1?"男":"女")+"\t"
                            +student.getTeacherId()+"\t"
                            +student.getComment());
                        }
                    }
                    System.out.println("===================================");
                    break;
                case 2:
                    System.out.println("要修改学员编号：\n");
                    int stuId = scan.nextInt();
                    System.out.println("要修改学员评语：\n");
                    String comments = scan.next();
                    Datas datas2 = clientBiz.doUpdate(stuId, comments);
                    if (SysConstants.SYS_SUCCESS.getName().equals(datas2.getFlag())) {
                        System.out.println("修改成功");
                    } else {
                        System.out.println("修改失败");
                    }
                    break;
                case 3:
                    System.out.println("输入删除学生编号：\n");
                    int stuId3 = scan.nextInt();
                    Datas datas3 = clientBiz.doDelete(stuId3);
                    if (SysConstants.SYS_SUCCESS.getName().equals(datas3.getFlag())) {
                        System.out.println("删除成功");
                    } else {
                        System.out.println("删除失败");
                    }
                    break;
                default:
                        System.out.println("退出成功");
                        break;
            }
        }
    }
}
